package com.yune.activity.login;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.ViewModelProvider;

import com.yune.R;
import com.yune.databinding.ActivityLoginBinding;

public class LoginActivity extends AppCompatActivity {
    private ActivityLoginBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //set设置，content内容
        binding=DataBindingUtil.setContentView(this,R.layout.activity_login);
/**创建ViewModelProvider，它将通过给定工厂创建ViewModel，并将它们保留在给定ViewModelStoreOwner的存储中。
 */
        LoginViewModel vm = new ViewModelProvider(this, new ViewModelProvider.AndroidViewModelFactory(getApplication())).get(LoginViewModel.class);
        binding.setVm(vm);
        //LifecycleOwner生命周期所有者  cycle周期
        binding.setLifecycleOwner(this);
        vm.setBinding(binding,this);
        //SupportActionBar 支撑杆  Support支撑，ActionBar 操作栏，Display显示器、陈列  HomeAsUp Enabled启用
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);//HomeButtonEnabled主页按钮启用
        setTitle(R.string.login);
    }

    @Override
    //OptionsItemSelected 选项项目选择
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        finish();
        return super.onOptionsItemSelected(item);
    }
}
